<?php
	session_start();

	//Conexión a la bd
	$link = mysqli_connect('localhost', 'root', '') or die("Failed to connect to MySQL: " . mysql_error());
	if (mysqli_connect_errno()) {
	        echo 'Failed to connect to MySQL';
	        exit;
	}
	$sql = "USE web_db";
	$query = mysqli_query($link,$sql);

	$date = date('Y-m-d');
	$desc = $_POST['descrip'];
	$rank = $_POST['rank_list'];

	//Coger el siguiente número de noticia
	$sql = "SELECT MAX(n_nr)
			FROM news";
	$query = mysqli_query($link,$sql);
	$aux = mysqli_fetch_row($query);
	$news_nr = $aux[0] + 1;

	//Inserción de datos
	$sql = "INSERT INTO news (n_nr, date, description, workstation) VALUES ('$news_nr', '$date', '$desc', '$rank')";
	$data = mysqli_query($link,$sql) or die($mysqli->error);
    if($data){
    	echo "News registered";
    	echo "<br>";
    }
    header("location:news_page.php");

?>